package com.ywyself.controller.api;

import com.jfinal.core.ActionKey;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.ywyself.common.pool.DataPool;
import com.ywyself.controller.base.YsController;
import com.ywyself.ext.kit.YsKit;
import com.ywyself.service.ArticleService;

/**
 *
 * @author YuWenYue
 * @date 2017年10月22日 下午7:56:48
 */
public class ApiArticleController extends YsController {

	@ActionKey("/api/article")
	public void index() {
		int currentPageNumber = getParaToInt(0, 1);
		int pageSize = getParaToInt(1, DataPool.getPageSize());
		Page<Record> page = ArticleService.EXC.page(currentPageNumber, pageSize);
		YsKit.ok()
				.set("page", currentPageNumber)
				.set("totalPage", page.getTotalPage())
				.set("count", page.getTotalRow())
				.data(page.getList())
				.render(this);
	}

	@ActionKey("/api/article/recent")
	public void recent() {
		int currentPageNumber = getParaToInt(0, 1);
		int pageSize = getParaToInt(1, DataPool.getPageSize());
		Page<Record> page = ArticleService.EXC.pageRecent(currentPageNumber, pageSize);
		YsKit.ok()
				.set("page", currentPageNumber)
				.set("totalPage", page.getTotalPage())
				.set("count", page.getTotalRow())
				.data(page.getList())
				.render(this);
	}

	@ActionKey("/api/article/hot")
	public void hot() {
		int currentPageNumber = getParaToInt(0, 1);
		int pageSize = getParaToInt(1, DataPool.getPageSize());
		Page<Record> page = ArticleService.EXC.pageTop(currentPageNumber, pageSize, true);
		YsKit.ok()
				.set("page", currentPageNumber)
				.set("totalPage", page.getTotalPage())
				.set("count", page.getTotalRow())
				.data(page.getList())
				.render(this);
	}
}
